using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.VisualStudio.Modeling;

namespace Evaluant.EussDSL
{
    /// <summary>
    /// Rule used to detect the actual multiplicity of a reference
    /// </summary>
    [RuleOn(typeof(RuleNew), FireTime = TimeToFire.TopLevelCommit)]
    public sealed class AddRuleRule : AddRule
    {
        public override void ElementAdded(ElementAddedEventArgs e)
        {
            foreach (ModelElement me in e.ModelElement.Store.ElementDirectory.AllElements)
            {
                if (me is ReferenceNewShape)
                {
                    MultiplicityVerifier.VerifyReferenceNew((ReferenceNewShape)me, null, null);
                }
            }
        }
    }

    /// <summary>
    /// Rule used to detect the actual multiplicity of a reference
    /// </summary>
    [RuleOn(typeof(RuleNew), FireTime = TimeToFire.TopLevelCommit)]
    public sealed class DeleteRuleRule : DeleteRule
    {
        public override void ElementDeleted(ElementDeletedEventArgs e)
        {
            foreach (ModelElement me in e.ModelElement.Store.ElementDirectory.AllElements)
            {
                if (me is ReferenceNewShape)
                {
                    MultiplicityVerifier.VerifyReferenceNew((ReferenceNewShape)me, null, null);
                }
            }
        }
    }
}
